package discovery

import (
	"context"
	"time"
)

// ServiceInfo represents information about a service instance
type ServiceInfo struct {
	ID        string
	Name      string
	Address   string
	Port      int
	Metadata  map[string]string
	Status    ServiceStatus
	LastSeen  time.Time
	StartTime time.Time
}

// ServiceStatus represents the status of a service
type ServiceStatus string

const (
	StatusUp      ServiceStatus = "up"
	StatusDown    ServiceStatus = "down"
	StatusWarning ServiceStatus = "warning"
)

// ServiceDiscovery defines the interface for service discovery
type ServiceDiscovery interface {
	// Register registers a service instance
	Register(ctx context.Context, service *ServiceInfo) error

	// Deregister removes a service instance
	Deregister(ctx context.Context, serviceID string) error

	// GetService gets a service instance by ID
	GetService(ctx context.Context, serviceID string) (*ServiceInfo, error)

	// ListServices lists all service instances
	ListServices(ctx context.Context) ([]*ServiceInfo, error)

	// ListServicesByName lists service instances by name
	ListServicesByName(ctx context.Context, serviceName string) ([]*ServiceInfo, error)

	// Watch watches for service changes
	Watch(ctx context.Context) (<-chan *ServiceEvent, error)

	// ReportStatus reports service status
	ReportStatus(ctx context.Context, serviceID string, status ServiceStatus) error
}

// ServiceEvent represents a service discovery event
type ServiceEvent struct {
	Type      ServiceEventType
	Service   *ServiceInfo
	Timestamp time.Time
}

// ServiceEventType represents the type of service event
type ServiceEventType string

const (
	EventTypeRegistered   ServiceEventType = "registered"
	EventTypeDeregistered ServiceEventType = "deregistered"
	EventTypeModified     ServiceEventType = "modified"
	EventTypeStatusChange ServiceEventType = "status_change"
)
